﻿@using Apps.Web.Core;
@using Apps.Models.Sys;
@using Apps.Common;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";

    List<PermModel> perm = ViewBag.perm;

    if (perm == null)
    {
        perm = new List<PermModel>();
    }

}
<script src="@Url.Content("~/Scripts/jquery.easyui.plus.js")" type="text/javascript"></script>
<div id="modalwindow" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
<table>
    <tr>
        <td style="vertical-align:top">
            <div class="mvctool">
                @Html.ToolButton("btnCreate", "icon-add", "新增", true, perm, "Create")
                @Html.ToolButton("btnEdit", "icon-edit", "编辑", true, perm, "Edit")
                @Html.ToolButton("btnDelete", "icon-remove", "删除", true, perm, "Delete")
            </div>
            <table id="List"></table>
        </td>
        <td style="width : 210px; padding-left : 5px; vertical-align : top">
            <div class="mvctool">
                @Html.ToolButton("btnCreateOpt", "icon-add", "新增操作码", true, perm, "Create")
                @Html.ToolButton("btnDeleteOpt", "icon-remove", "删除操作码", true, perm, "Delete")
            </div>
            <table id="ListOpt"></table>
        </td>
    </tr>

</table>
<script type="text/javascript">
    $(function () {
        $('#List').treegrid({
            url: '@Url.Action("GetList")',
            width: $(window).width() - 270,
            method: 'post',
            height: $(window).height() - 35,
            fitColumns: true,
            treeField: 'Name',
            idField: 'Id',
            pagination: false,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            //rownumbers: true,//行号
            columns: [[
                { field: 'Id', title: '唯一标识', width: 120 },
                { field: 'Name', title: '名称', width: 220, sortable: true },
                { field: 'EnglishName', title: '英文名称', width: 80, sortable: true, hidden: true },
                { field: 'ParentId', title: '上级Id', width: 80, sortable: true },
                { field: 'Url', title: '链接地址', width: 80, sortable: true },
                { field: 'Iconic', title: '图标', width: 80, sortable: true },
                { field: 'Sort', title: '排序号', width: 80, sortable: true },
                { field: 'Remark', title: '说明', width: 80, sortable: true },
                {
                    field: 'Enable', title: '是否启用', width: 60, align: 'center', formatter: function (value) {
                        if (value) {
                            return "<img src='/Content/Images/icon/pass.png'/>";
                        } else {
                            return "<img src='/Content/Images/icon/no.png'/>";
                        }
                    }
                },
                { field: 'CreatePerson', title: '创建人', width: 80, sortable: true },
                { field: 'CreateTime', title: '创建时间', width: 120, sortable: true },
                {
                    field: 'IsLast', title: '是否最后一项', align: 'center', width: 100, formatter: function (value) {
                        if (value) {
                            return "是";
                        } else {
                            return "否";
                        }
                    }
                },
            ]],
            onClickRow: function (index, data) {
                var row = $('#List').treegrid('getSelected');
                if (row != null) {
                    $('#ListOpt').datagrid({
                        url: '@Url.Action("GetOptListByModule")?mid=' + row.Id
                    });
                }
            }
        });

        $('#ListOpt').datagrid({
            url: '@Url.Action("GetOptListByModule")',
            width: 255,
            method: 'post',
            height: $(window).height() - 35,
            fitColumns: true,
            sortName: 'Sort',
            sortOrder: 'asc',
            idField: 'Id',
            pageSize: 1000,
            pagination: false,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            //rownumbers: true,//行号
            columns: [[
                { field: 'Id', title: '', width: 80, hidden: true },
                { field: 'Name', title: '名称', width: 80, sortable: true },
                { field: 'KeyCode', title: '操作码', width: 80, sortable: true },
                { field: 'ModuleId', title: '所属模块', width: 80, sortable: true, hidden: true },
                {
                    field: 'IsValid', title: '是否验证', width: 80, align: 'center', formatter: function (value) {
                        if (value) {
                            return "<img src='/Content/Images/icon/pass.png'/>";
                        } else {
                            return "<img src='/Content/Images/icon/no.png'/>";
                        }
                    }
                },
                { field: 'Sort', title: '排序', width: 80, sortable: true }
            ]]
        });

        //自动宽高
        $(window).resize(function () {
            $('#List').datagrid('resize', {
                width: $(window).width() - 270,
                height: $(window).height() - 35
            });

            $('#ListOpt').datagrid('resize', {
                height: $(window).height() - 35
            })
        });
    })
</script>

<script type="text/javascript">
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
            $("#List").treegrid('reload');
        else
            $("#List").treegrid('load');
    }
    function frameReturnByReloadOpt(flag) {
        if (flag)
            $("#ListOpt").datagrid('load');
        else
            $("#ListOpt").datagrid('reload');
    }
    function frameReturnByMes(mes) {
        $.messageBox5s('提示', mes);
    }

    $(function () {
        $('#btnCreate').click(function () {
            var row = $('#List').treegrid('getSelected');
            $("#modalwindow").html("<iframe width='100%' height='98%' scrolling='no' frameborder='0'' src='/SysModule/Create?id=" + (row != null ? row.Id : "0") + "&Ieguid=" + GetGuid() + "'></iframe>");
            $("#modalwindow").window({ title: '新增', width: 700, height: 400, iconCls: 'icon-add' }).window('open');
        });

        $("#btnEdit").click(function () {
            var row = $('#List').treegrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='/SysModule/Edit?mid=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '编辑', width: 700, height: 430, iconCls: 'icon-edit' }).window('open');
            } else { $.messageBox5s('提示', '@Suggestion.PlaseChooseToOperatingRecords'); }
        });

        $('#btnDelete').click(function () {
            var row = $('#List').treegrid('getSelected');
            if (row != null) {
                $.messager.confirm('提示', '确认删除', function (r) {
                    if (r) {
                        $.post('@Url.Action("Delete")?mid=' + row.Id, function (data) {
                            if (data.tag == 1) {
                                $('#List').treegrid('reload');
                                $.messageBox5s('提示', data.message);
                            } else {
                                $.messageBox5s('提示', data.message);
                            }
                        }, "json");
                    }
                });
            } else {
                $.messageBox5s('提示', '@Suggestion.PlaseChooseToOperatingRecords');
            }
        });

        $('#btnCreateOpt').click(function () {
            var row = $('#List').treegrid('getSelected');
            if (row != null) {
                if (row.IsLast) {
                    $("#modalwindow").html("<iframe width='100%' height='98%' scrolling='no' frameborder='0'' src='/SysModule/CreateOperate?moduleId=" + (row != null ? row.Id : "0") + "&Ieguid=" + GetGuid() + "'></iframe>");
                    $("#modalwindow").window({ title: '新增操作码', width: 500, height: 330, iconCls: 'icon-edit' }).window('open');
                } else {
                    debugger;
                    $.messageBox5s('提示', '只有最后一项的菜单才能设置操作码!');
                }
            } else {
                $.messageBox5s('提示', '请选择一个要赋予操作码的模块!');
            }
        });

        $('#btnDeleteOpt').click(function () {
            var row = $('#ListOpt').datagrid('getSelected');
            if (row != null) {
                $.messager.confirm('提示', '您确定要删除' + row.Name + '这个操作码吗?', function (r) {
                    if (r) {
                        debugger;
                        $.post('@Url.Action("DeleteOperate")?mid=' + row.Id, function (data) {
                            if (data.tag == 1) {
                                $('#ListOpt').datagrid('reload');
                                $.messageBox5s('提示', data.message);
                            } else {
                                $.messageBox5s('提示', data.message);
                            }
                        });
                    } else {
                        $.messageBox5s('提示', '请选择一个要赋予操作码的模块!');
                    }
                });
            } else {
                $.messageBox5s('提示', '@Suggestion.PlaseChooseToOperatingRecords');
            }
        })
    })


</script>

